﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Marbles.Core.Settings
{
    public static class Environment
    {
        public static bool IsUnix()
        {
            int platform = (int)System.Environment.OSVersion.Platform;
            return ((platform == 4) || (platform == 6) || (platform == 128));
        }

        public static bool IsMono()
        {
            Type t = Type.GetType("Mono.Runtime", false);
            return (t == null);
        }


        public static string TwitterFormat(string subject)
        {
            string value = subject;
            value = Regex.Replace(value, "(^|[\n ])([\\w]+?://[\\w]+[^ \"\n\r\t< ]*)", "$1<a href=\"$2\" target=\"_blank\">$2</a>");
            value = Regex.Replace(value, "(^|[\n ])((www|ftp)\\.[^ \"\t\n\r< ]*)", "$1<a href=\"http://$2\" target=\"_blank\">$2</a>");
            value = Regex.Replace(value, "\\@(\\w+)", "<a href=\"http://www.twitter.com/$1\" target=\"_blank\">@$1</a>");
            value = Regex.Replace(value, "\\#(\\w+)", "<a href=\"http://search.twitter.com/search?q=$1\" target=\"_blank\">#$1</a>");
            return value;
        }

        public static DateTime GetBuildDate()
        {
            return new DateTime(2000, 1, 1).AddDays(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build);
        }

        public static Int32 GetBuildNumber()
        {
            return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build;
        }

    }
}
